﻿<!--#include file="inc/common.asp" -->
<%
'保存引用信息的功能模块
'
'author: evan zhao
'

  call openDB
    
  dim actionType,content_id, track_id
  dim url, title, excerpt, user_name, user_id, host_name, host_url
  dim blogItem
  content_id = trim(request("content_id"))

  if content_id="" then
    message("文章不存在")
    return
  else
    content_id = clng(content_id)  
  end if
  
  actionType = filterHTML(request("actionType"))
  track_id = filterHTML(request("track_id"))
  
  if (actionType="doSave")  and  userRightObj.canReply  then
    'todo判断是否重复刷新
  
  
    url = filterHTML(request.form("url"))
    if url="" or lcase(url)="http://" then
        message("请提供URL")
        response.end
    end if
    
    title = filterHTML(request.form("title"))
    if title="" then
        title = url
    end if    
    
    host_url = request.form("host_url")
    host_name = filterHTML(request.form("host_name"))
    if host_name="" then
        host_name = host_url
    end if
    
    sql = "select track_id, blog_id, content_id,  url, title, excerpt, user_name, user_id, host_name, host_url from blog_track where track_id=0 "
    rs.open sql, conn, 1, 3
    rs.addNew()
    rs("blog_id") = blogObj.blogId
    rs("content_id") = content_id
    rs("url") = url
    rs("title") = title
    rs("host_name") =  host_name
    rs("host_url") = host_url
    rs("excerpt") = filterHTML2(request("excerpt"),true)
    rs("user_name") = filterHTML(request("user_name"))
    rs.update()
    
    track_id = rs("track_id")
    rs.close()
    
    sql = " update blog_content set track_count=track_count+1, update_time=now() where content_id=" & content_id
    conn.execute(sql)
    
    
    set blogItem = new BlogItemClass
    call blogItem.reload(content_id)      
    
    closeDB()
    response.clear
    response.redirect("detail.asp?blog_id=" & blogObj.blogId & "&cat_id=" & blogCatObj.catId & "&content_id=" & content_id & "&#track" & track_id)
    response.end
    
  
  elseif actionType="doDelete" and track_id<>"" and userRightObj.canDelete then
    sql = " select track_id,user_id from blog_track where track_id=" & track_id & " and content_id="&content_id
    rs.open sql,conn,1,3 
    if not rs.bof and not rs.eof and (rs("user_id")=userObj.userId or userRightObj.canDelete) then
        rs.delete()
        rs.close()
                
        sql = " update blog_content set track_count=track_count-1, update_time=now() where content_id=" & content_id
        conn.execute(sql)
    end if
    

    set blogItem = new BlogItemClass
    call blogItem.reload(content_id)      

    closeDB()
    response.clear
    call redirect("detail.asp?blog_id=" & blogObj.blogId & "&cat_id=" & blogCatObj.catId & "&content_id=" & content_id & "&#trackback" )
    response.end
  
  else
    closeDB()
    response.clear
    call transfer("detail.asp")  
  end if      


    
%>
<!--#include file="inc/end.asp" -->